<?php
require_once 'vendor/autoload.php';

// 初始化应用
$app = new \think\App();
$app->initialize();

echo "测试日志API...\n";

// 获取Token
$loginData = [
    'username' => 'admin',
    'password' => '123456'
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://localhost:8000/api/auth/login');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($loginData));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json',
    'Accept: application/json'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

echo "登录测试:\n";
echo "HTTP状态码: $httpCode\n";
echo "响应: $response\n";

$loginResult = json_decode($response, true);
if ($loginResult && isset($loginResult['data']['token'])) {
    $token = $loginResult['data']['token'];
    echo "获取到Token: $token\n\n";
    
    // 测试日志列表API
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'http://localhost:8000/api/logs');
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'Authorization: Bearer ' . $token,
        'Accept: application/json'
    ]);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
    $response = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    
    echo "日志列表测试:\n";
    echo "HTTP状态码: $httpCode\n";
    echo "响应: $response\n\n";
    
    // 测试日志统计API
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'http://localhost:8000/api/logs/statistics');
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        'Authorization: Bearer ' . $token,
        'Accept: application/json'
    ]);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
    $response = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    
    echo "日志统计测试:\n";
    echo "HTTP状态码: $httpCode\n";
    echo "响应: $response\n\n";
    
} else {
    echo "登录失败，无法获取Token\n";
} 